package com.tianqu.tms.www.member.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.www.member.controller.MemberUDBaseResultController;
import com.tianqu.tms.www.member.viewhelper.MemberInputViewHelper;
/**
 * 商户信息修改结果页Action
 * 
 * @author tianshifu
 *
 */
public class MemberUDBaseResultAction extends TmsAction {

	private static final String MEMBERID = "memId";//会员ID
	
	private static final String SYSPATH = "sysPath";
	
	private static final String LEFTLINE ="/";
	
	private static final String TMSPATH = "/tmsweb";
	
	private static final String IMGLIST = "imgList";//用于存放图片对象的list
	
	private static final String OFF="off";//用于结果页面提示
	
	private static final String UPDATEMESSAGE = "updateMessage";
	
	private Logger logger = Logger.getLogger(MemberUDBaseResultAction.class);

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		//给个memberID.,用于跳转
		String memberID =(String)uc.getAttribute(MEMBERID);
		//uc.removeAttribute(MEMBERID);
		
		MemberInputViewHelper view = (MemberInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		view.setMemberId(memberID);
		
		Member member = Member.getInstance();
		//判断商户名称是否重复
		if(!view.getRealName().equals(view.getRealNameSave())){
			boolean result1 = member.isRepeatMemberName(view.getRealName(),1);
			if(result1 == true){
				setErrorsToRequest(request, TmsConstants.U4001 ,null);
				request.setAttribute(TmsConstants.VIEWHELP, view);
				return mapping.getInputForward();
			}
		}
		//判断商户短名是否重复
		if(!view.getShortName().equals(view.getShortNameSave())){
			boolean result2 = member.isRepeatMemberName(view.getShortName(),2);
			if(result2 == true){
				setErrorsToRequest(request, TmsConstants.U4002 ,null);
				request.setAttribute(TmsConstants.VIEWHELP, view);	
				return mapping.getInputForward();
			}
		}
		
		MemberUDBaseResultController controller = new MemberUDBaseResultController();
		String sysPath = request.getSession().getServletContext().getRealPath(LEFTLINE).replace(TMSPATH, TmsConstants.BLANK);
		uc.setAttribute(SYSPATH, sysPath);
		controller.execute(uc);
		
		uc.removeAttribute(IMGLIST);//添加完之后清空图片viewhelp
		
		request.setAttribute(TmsConstants.VIEWHELP, view);		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
